package com.zsf.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zsf.pojo.Administrators;
import com.zsf.service.AdminstratorsService;
import com.zsf.serviceImp.AdminstratorsServiceImp;

/**
 * Servlet implementation class AdminLoginServlet
 */
public class AdminLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	AdminstratorsService adminstratorsService=new AdminstratorsServiceImp();

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		Administrators administrators=new Administrators();
		String account=request.getParameter("account");
		String password=request.getParameter("password");
		PrintWriter pw=response.getWriter();
		System.out.println(password+"         "+account);
		administrators.setAccount(account);
		administrators.setPassword(password);
		administrators=adminstratorsService.getAdminByAP(administrators);
		if(administrators!=null){
			request.getSession().setAttribute("current_admin", administrators);
			pw.print("<script>alert('登录成功，点击确定跳转到商场管理页面'); window.location.href='product';</script>");
		}else{
			pw.print("<script>alert('登录失败，请重新登录'); window.location.href='adminLogin.jsp';</script>");
		}
	}

}
